#ifndef DESIGNER_H
#define DESIGNER_H

#include <QWidget>
#include <QGraphicsItem>
#include <QGraphicsScene>
#include <QGraphicsEllipseItem>
#include <QGraphicsView>
#include <QList>
#include <QListIterator>
#include "myshape.h"
#include "node.h"
#include "link.h"
#include "circle.h"
#include "circleDep.h"
#include "dep.h"

#include "xmlObj.h"
#include "xmlBlock.h"
#include "xmlLink.h"
#include "xmlNode.h"
#include "xmlDep.h"
#include <QQueue>
#include <typeinfo>

class circle;
class circleDep;
class mainwindow;



class designer : public QWidget
{
    Q_OBJECT

public:
    designer(mainwindow *myMainWindow);
    ~designer();

private:
    QGraphicsScene *scene;
    QGraphicsView *view;
    mainwindow *myMainWindow;

    typedef QPair<myshape *, myshape *> ShapePair;
    //usati dagli slots bringToFront() sendToBack()
    int minZ;
    int maxZ;
    int seqNumber; //usato per dare un nome univoco agli item

    QQueue<QString> *queueNameTerminalList; // coda per l'assegnamento automatico dei terminali
    QQueue<QString> *queueNameIdentifierList; //coda per l'assegnamento automatico degli ID dei blocchi e dei circle
    QQueue<QString> *queueNameIdentifierLinkList; // coda per l'assegnamento automatico degli ID dei link

private:
    void setupShape(myshape *n);
    //void setupCircle(circle *c);
    void setZValue(int z);
    myshape *selectedShape() const;
    link *selectedLink() const;
    ShapePair selectedShapePair() const;

public:
    void addNode();
    void addLink();
    void addCircle();
    void addDep();
    void addCircleDep();
    void bringToFront();
    void sendToBack();
    //void properties();
    QQueue<QString> *getNameTerminalList();
    QQueue<QString> *getNameIdentifierList();
    QQueue<QString> *getNameIdentifierLinkList();

    void addNodeFromParser(xmlBlock *b);
    void addLinkFromParser(xmlLink *l);
    void addCircleFromParser(xmlNode *n);
    circleDep* addCircleDepFromParser();
    void addDepFromParser(QString triggerId, xmlBlock *b, int count);
    void addMergedDepFromParser(xmlBlock *b, QList<xmlDep *> depMergedTrigger);
    void setupShapeFromParser(myshape *n);

public:
    QGraphicsView *getView();
    QGraphicsScene *getScene();
    void itemIsRemoved();

private:
    QList<node *> nodeList;
    QList<circle *> circleList;
    QList<link *> linkList;

public:
    QList<node *> getNodeList();
    QList<circle *> getCircleList();
    QList<link *>  getLinkList();
    void setNodeList(QList<node *> nodeList);
    void setCircleList(QList<circle *> circleList);
    void setLinkList(QList<link *> linkList);

};

#endif // DESIGNER_H
